package com.yuanian.ecsplus.model.entity;

import com.yuanian.console.entity.ConsoleUserDO;
import com.yuanian.ecsplus.annotation.Hidden;
import com.yuanian.ecsplus.annotation.Id;
import com.yuanian.ecsplus.annotation.ReadOnly;
import com.yuanian.ecsplus.cache.CacheManager;
import com.yuanian.ecsplus.entity.DictionaryEntity;
import com.yuanian.ecsplus.meta.entity.MetaEntity;
import com.yuanian.ecsplus.model.EcsModel;
import com.yuanian.ecsplus.model.vo.BaseVoModel;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 基础实体类
 */
public abstract class BaseModel extends EcsModel {

    protected MetaEntity metaEntity;

    public BaseModel() {
        this.metaEntity = CacheManager.getInstance().getMetaEntity(this.getClass());
    }

    public BaseModel(boolean createBoDataFlag) {
        this();
        if (createBoDataFlag) {
            this.metaEntity.create(new HashMap(), this);
        }
    }

    public BaseModel(Map data) {
        this();
        this.metaEntity.create(data, this);
    }

    //-------------通用字段--------------------
   @Id
    protected String objectId;
    @ReadOnly
    protected BigDecimal bizVersion;
    @ReadOnly
    protected String boDataId;

    @ReadOnly
    protected String boDefineId;

    @ReadOnly
    protected String boTypeDefineHistoryId;

    protected String name;

    protected String code;
    @ReadOnly
    protected String rowNum;

    @ReadOnly
    protected String sourceBizVersionId;
    @ReadOnly
    protected String boVersionStatus;

    @ReadOnly
    protected String appId;

    @ReadOnly
    protected String wfStatus;

    @ReadOnly
    protected String wfInstanceId;

    @ReadOnly
    protected Date wfSubmitTime;

    @ReadOnly
    protected Date wfEndTime;

    @ReadOnly
    protected DictionaryEntity createOrgId;

    @ReadOnly
    protected String boDataStatus;

    @ReadOnly
    protected String bizVersionId;

    @ReadOnly
    protected Integer versionNumber;

    @ReadOnly
    protected String tenantId;

    @ReadOnly
    protected ConsoleUserDO createBy;

    @ReadOnly
    protected Date createDate;

    @ReadOnly
    protected ConsoleUserDO updateBy;

    @ReadOnly
    protected Date updateDate;

    @ReadOnly
    protected String updateLogin;

    @ReadOnly
    protected String pOrgId;

    @ReadOnly
    protected String pAppId;

    @ReadOnly
    protected Boolean pDeleted;

    //-------------通用方法--------------------
    public void save() {
        metaEntity.save(this);
    }

    public BaseModel create(Map data) {
        this.metaEntity.create(data, this);
        return this;
    }

    public BaseModel create() {
        this.metaEntity.create(new HashMap(), this);
        return this;
    }

    public void update() {
        metaEntity.update(this);
    }

    public void insert() {
        metaEntity.insert(this);
    }

    public boolean delete() {
        metaEntity.delete(this);
        return true;
    }

    public void issue() {
        metaEntity.issue(this);
    }

    /**
     * 实体转VO
     */
    public <C extends BaseVoModel> C toVo(Class<C> clz) {
        Map map = this.metaEntity.getMetaClass().toMap(this);
        this.metaEntity.getPlatformSupport().boMapFullDataConvert(map, this.metaEntity.getMetaClass().getApiName());
        return (C) CacheManager.getInstance().getMetaVo(clz).getMetaClass().toEntity(map);
    }

    /**
     * 实体转map
     * @return
     */
    public Map toMap() {
        return this.metaEntity.getMetaClass().toMap(this);
    }

   public String getObjectId() {
        return objectId;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }

    public BigDecimal getBizVersion() {
        return bizVersion;
    }

    public void setBizVersion(BigDecimal bizVersion) {
        this.bizVersion = bizVersion;
    }

    public String getBoDataId() {
        return boDataId;
    }

    public void setBoDataId(String boDataId) {
        this.boDataId = boDataId;
    }

    public String getBoDefineId() {
        return boDefineId;
    }

    public void setBoDefineId(String boDefineId) {
        this.boDefineId = boDefineId;
    }

    public String getBoTypeDefineHistoryId() {
        return boTypeDefineHistoryId;
    }

    public void setBoTypeDefineHistoryId(String boTypeDefineHistoryId) {
        this.boTypeDefineHistoryId = boTypeDefineHistoryId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getRowNum() {
        return rowNum;
    }

    public void setRowNum(String rowNum) {
        this.rowNum = rowNum;
    }

    public String getSourceBizVersionId() {
        return sourceBizVersionId;
    }

    public void setSourceBizVersionId(String sourceBizVersionId) {
        this.sourceBizVersionId = sourceBizVersionId;
    }

    public String getBoVersionStatus() {
        return boVersionStatus;
    }

    public void setBoVersionStatus(String boVersionStatus) {
        this.boVersionStatus = boVersionStatus;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getWfStatus() {
        return wfStatus;
    }

    public void setWfStatus(String wfStatus) {
        this.wfStatus = wfStatus;
    }

    public String getWfInstanceId() {
        return wfInstanceId;
    }

    public void setWfInstanceId(String wfInstanceId) {
        this.wfInstanceId = wfInstanceId;
    }

    public Date getWfSubmitTime() {
        return wfSubmitTime;
    }

    public void setWfSubmitTime(Date wfSubmitTime) {
        this.wfSubmitTime = wfSubmitTime;
    }

    public Date getWfEndTime() {
        return wfEndTime;
    }

    public void setWfEndTime(Date wfEndTime) {
        this.wfEndTime = wfEndTime;
    }

    public DictionaryEntity getCreateOrgId() {
        return createOrgId;
    }

    public void setCreateOrgId(DictionaryEntity createOrgId) {
        this.createOrgId = createOrgId;
    }

    public String getBoDataStatus() {
        return boDataStatus;
    }

    public void setBoDataStatus(String boDataStatus) {
        this.boDataStatus = boDataStatus;
    }

    public String getBizVersionId() {
        return bizVersionId;
    }

    public void setBizVersionId(String bizVersionId) {
        this.bizVersionId = bizVersionId;
    }

    public Integer getVersionNumber() {
        return versionNumber;
    }

    public void setVersionNumber(Integer versionNumber) {
        this.versionNumber = versionNumber;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }



    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public ConsoleUserDO getCreateBy() {
        return createBy;
    }

    public void setCreateBy(ConsoleUserDO createBy) {
        this.createBy = createBy;
    }

    public ConsoleUserDO getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(ConsoleUserDO updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Boolean getpDeleted() {
        return pDeleted;
    }

    public void setpDeleted(Boolean pDeleted) {
        this.pDeleted = pDeleted;
    }

    public String getUpdateLogin() {
        return updateLogin;
    }

    public void setUpdateLogin(String updateLogin) {
        this.updateLogin = updateLogin;
    }

    public String getpOrgId() {
        return pOrgId;
    }

    public void setpOrgId(String pOrgId) {
        this.pOrgId = pOrgId;
    }

    public String getpAppId() {
        return pAppId;
    }

    public void setpAppId(String pAppId) {
        this.pAppId = pAppId;
    }
}
